import random
def pin(type):
  "this function generates a random pin # valid to the type (total number of pin code possibilities)"
  a = 0
  b = type - 1
  return random.randint(a,b)

def randomkey(pins, bits, macs) :
    bits = int(bits)
    rdmkey = []
    count = int()
    while count != (pins) :
        rdmkey.append(pin(bits))
        if count >= 1 :
            num1 = rdmkey[len(rdmkey) - 2]
            num2 = rdmkey[len(rdmkey) - 3]
            if num1 == num2 :
                pretest = num1
            else : 
                pretest = 1000
            while abs(rdmkey[len(rdmkey) - 2] - rdmkey[-1]) > macs or rdmkey[-1] == pretest :
                rdmkey[-1] = pin(bits)
        count += 1
    return rdmkey

def lint(list) :
    "this function takes a list of strings and turns it into a list of integers"
    test = []
    if type(list) != type(test) :
        return list
    list = [int(n) for n in list]
    return list

def lstr(list) :
    "this function turns a list of integers into a list of strings"
    test = []
    if type(list) != type(test) :
        return list
    list = [str(n) for n in list]
    return list

def subkey(code, bits, macs, level) :
    "this function generates the next key in a 2 step progression schema"
    code = list(code)
    code = lint(code)
    if level == 0 :
        code = ''.join(code)
        return code
    elif level == 1 :
        code[2] = abs(code[2] + 2) % bits
        if code[2] <= 1 :
            code[3] = abs(code[3] + 2) % bits
        code = lstr(code)
        code = ''.join(code)
    #elif level == 2 :
        
        
    return code
    

#print randomkey(6, 10, 6)
print subkey('05007', 10, 6, 1)        
    
